//#define _CRT_SECURE_NO_WARNINGS
#include <tchar.h>
#include <windows.h>

#include <iostream>
using namespace std;

#pragma comment(lib,"Urlmon.lib")

/// <summary>
/// 获取电脑分区
/// </summary>
int  diskInfomation()
{
  //  TCHAR Driver[MAX_PATH] = { 0 };
   // DWORD dwRet = GetLogicalDriveStrings(MAX_PATH, Driver);
    DWORD dwRet = GetLogicalDriveStrings(0, NULL);
    if (dwRet > 0)
    {
        TCHAR* pbuffer = new TCHAR(dwRet + 10);//字符
        //清空内存
        //最后*sizeof(TCHAR) 一个字节，一个字符
        ZeroMemory(pbuffer,(dwRet*10)*sizeof(TCHAR));//字节
        dwRet = GetLogicalDriveStrings(dwRet * 10, pbuffer);
        if (dwRet > 0)
        {
            TCHAR* psingnal = pbuffer;
            do {
                if (*psingnal) 
                {
                    TCHAR* rs = psingnal;
                    cout << psingnal << endl;
                    psingnal += _tcslen(psingnal) + 1;

                }
            } while (*psingnal);
        }
    }
    return 0;
}

//int WINAPI _tWinMain(HINSTANCE hInst, HINSTANCE hPrevInst, LPSTR args, int ncmdshow) 
int WINAPI _tWinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPTSTR lpCmdLine, int nCmdShow)
{
     int value= diskInfomation();
     //  MessageBox(NULL,_T("我的第一个c++程序"),_T("我是标题"),MB_YESNOCANCEL|MB_ICONERROR|MB_DEFBUTTON1);//默认按钮是哪个MB_DEFBUTTON1为第一个 高亮显示，
     //下载文件
       HRESULT href=  URLDownloadToFile(NULL,_T("https://pic3.zhimg.com/v2-5fb13110e1de13d4c11e6e7f5b8026da_r.jpg"), _T("F:\\1.jpg"),0, NULL);
       if (href == S_OK)
       {
           ///复制文件
           bool v = CopyFile(_T("F:\\1.jpg"), _T("D:\\1.jpg"),false);
           if (v)
           {
               MessageBox(NULL, _T("复制成功"), _T("TipTK"), MB_OK);
           }
           else
           {
               MessageBox(NULL, _T("复制失败"), _T("Tip"), MB_OK);
           }

           //移动文件
           bool v2 = MoveFile(_T("D:\\1.jpg"), _T("E:\\1.jpg"));
           if (v2)
           {
               MessageBox(NULL, _T("移动成功"), _T("Tip"), MB_OK);
           }
           else
           {
               DWORD d = GetLastError();
               if (d == ERROR_FILE_EXISTS)
               {
                   MessageBox(NULL, _T("文件已存在"), _T("Tip"), MB_OK);
               }
               else
               {
                   MessageBox(NULL, _T("移动失败"), _T("Tip"), MB_OK);
               }
           }

           ///异常处理
           bool v3 = CopyFile(_T("F:\\2.jpg"), _T("D:\\1.jpg"), false);
           if (v3)
           {
               MessageBox(NULL, _T("复制成功"), _T("TipTK"), MB_OK);
           }
           else
           {
               DWORD d = GetLastError();
               if (d == ERROR_FILE_NOT_FOUND)
               {
                   MessageBox(NULL, _T("文件不存在"), _T("Tip"), MB_OK);
               }
               else 
               {
                   MessageBox(NULL, _T("复制失败"), _T("Tip"), MB_OK);
               }
           }

         
           UINT  res= MessageBox(NULL,_T("下载成功,删除或者打开"),_T("Tip"), MB_YESNO);
           if (res == IDYES) 
           {  //删除文件
               bool v= DeleteFile(_T("F:\\1.jpg"));
               if (v) 
               {
                   MessageBox(NULL, _T("删除成功"), _T("Tip"), MB_OK);
               }
               else
               {
                   MessageBox(NULL, _T("删除失败"), _T("Tip"), MB_OK);
               }
           }
           else 
           {
               SHELLEXECUTEINFO shellInfo = { 0 };
               shellInfo.cbSize = sizeof(SHELLEXECUTEINFO);
               shellInfo.lpVerb = _T("open");
               shellInfo.lpFile = _T("F:\\1.jpg");
               shellInfo.nShow = SW_SHOW;
               BOOL bRet = ShellExecuteEx(&shellInfo);
           
           }

           //打开文件
        
       }
       else 
       {
           MessageBox(NULL, _T("下载失败"), _T("Tip"), MB_OK);
       }
     return 0;
}

